package com.kaguya.singleton;

/**
 * 单例模式 枚举方式实现
 * 枚举的底层其实就是静态的变量和静态方法，所以也是饿汉式的实现，且可以防止反射
 */
public class HungrySingletonTest2 {
    public static void main(String[] args) {
        Singleton singleton1 = Singleton.INSTANCE;
        Singleton singleton2 = Singleton.INSTANCE;

        System.out.println(singleton1 == singleton2);
        System.out.println(singleton1.hashCode());
        System.out.println(singleton2.hashCode());
    }

    enum  Singleton {
        INSTANCE;
        public void sayOK(){
            System.out.println("ok!");
        }
    }
}
